package com.magold.sprite;

import org.andengine.entity.IEntity;

/**
 * 
 * @author Eternity
 *
 */
public class MagoldSpriteWrapper extends MultiTextureSpriteFilter {
	private final float mBaseScaleFactor;
	
	public MagoldSpriteWrapper(IMultiTextureSprite pSprite, float pBaseScaleFactor) {
		super(pSprite);
		mBaseScaleFactor = pBaseScaleFactor;
	}

	@Override
	public void onAttached() {
		
	}
	
	@Override
	public void onDetached() {
		
	}
	

	// ======================
	// = base scale support =
	// ======================

	@Override
	public void setScaleX(float pScaleX) {
		mSprite.setScaleX(pScaleX * mBaseScaleFactor);
	}

	@Override
	public void setScaleY(float pScaleY) {
		mSprite.setScaleY(pScaleY * mBaseScaleFactor);
	}

	@Override
	public void setScale(float pScale) {
		mSprite.setScale(pScale * mBaseScaleFactor);
	}

	@Override
	public void reset() {
		mSprite.reset();
		
		this.setScale(1.0f);
	}
	
	@Override
	public void setZIndex(int pZIndex) {
		if (pZIndex == getZIndex()) return;
		
		super.setZIndex(pZIndex);
		
		IEntity parent = getParent();
				
		if (parent != null) {
			parent.sortChildren(false);
		}
	}

}
